package com.kfm.servlet;

import com.kfm.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 模拟查询了数据库返回了两个user对象

        User u = new User("admin", "123456");
        User u1 = new User("zhangsan", "123456");

        List<User> list = List.of(u, u1);
        req.setAttribute("users", list);
        req.getRequestDispatcher("index.jsp").forward(req, resp);
    }
}
